﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP.Electric.Common;

namespace HYRElectric.PowerSystem
{
	public partial class DlgDistributionCheck : System.Windows.Forms.Form
	{
		public DlgDistributionCheck()
		{
			this.InitializeComponent();
		}

		private void DlgDistributionCheck_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.xmlHelper.LoadXml(this.path, "Root");
			this.LoadDlgData();
		}

		private void DlgDistributionCheck_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYDistributionCheck", "Params"));
			string attribute = this.xmlHelper.GetAttribute("Type");
			if (!string.IsNullOrEmpty(attribute))
			{
				if (attribute == "0")
				{
					this.rdoView.Checked = true;
					return;
				}
				if (attribute == "1")
				{
					this.rdoProject.Checked = true;
				}
			}
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYDistributionCheck"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYDistributionCheck", "Params"));
			string value;
			if (this.rdoView.Checked)
			{
				value = "0";
			}
			else
			{
				value = "1";
			}
			this.xmlHelper.SetAttribute("Type", value);
			this.xmlHelper.SaveXml("");
		}

		private YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();

		private string path = Path.Combine(new string[]
		{
			Product.WorkingLocation + "DistributionCheck.xml"
		});

		private const string Root = "Root";

		private const string Node = "HYDistributionCheck";

		private const string ChildNode = "Params";

		private const string Type = "Type";
	}
}
